<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<!--<link href="../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">-->
		<link rel="stylesheet" type="text/css" href="../../../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />-->
		<link rel="stylesheet" type="text/css" href="../../../css/footer.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/gift_sell.css" />
		<style type="text/css">
			#content {
				/*padding-top: 0.763888rem;*/
				padding-top: 0.8rem;
			}
			
			a#fahuo {
				position: fixed;
				/*top: ;*/
				bottom: 0.3rem;
				z-index: 2;
			}
			
			a.del {
				position: relative;
				z-index: 20;
			}
		</style>
		<script src="../../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body style="overflow: auto;">
		<div id="wrap">
			<div id="main">
				<div id="header">
					<a id="headImg" href="javascript:history.go(-1)"><img class="headImg" src="../../../images/12.png" /></a>
					<p id="headTitle">商品购物车</p>
				</div>
				<div id="content" style="overflow: auto;">
					<div class="gift_sell_wap" style="overflow: auto;">
						<ul style="overflow: auto; height: auto;">
							<!--<li>
								<div class="gift_left foods_detail_pic">
									<img src="../../../images/coalltion/mianbao.jpg"/>
								</div>
								<div class="gift_right">
									<p id="shopName">红牛</p>
									<p id="shopPrice">金币:34</p>
									<p></p>
									
								</div>
								<div class="duihuan">
									<img src="../../../images/store/duihuan.png"/>
								</div>
							</li>-->
						</ul>
					</div>
					<a id="fahuo">发货</a>
				</div>
			</div>
		</div>

	</body>
	<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		function UrlSearch() {
			var name, value;
			var str = location.href; //取得整个地址栏
			var num = str.indexOf("?")
			str = str.substr(num + 1); //取得所有参数   stringvar.substr(start [, length ]

			var arr = str.split("&"); //各个参数放到数组里
			for(var i = 0; i < arr.length; i++) {
				num = arr[i].indexOf("=");
				if(num > 0) {
					name = arr[i].substring(0, num);
					value = arr[i].substr(num + 1);
					this[name] = value;
				}
			}
		}

		var Request = new UrlSearch();

		//获取会员信息
		$.ajax({
			type: "get",
			url: "http://47.104.13.109/member-service/auth/current?token=" + $.cookie("tokenRh"),
			async: true,
			success: function(res) {
				console.log(res)

				$.ajax({
					type: "get",
					url: "http://47.104.13.109/cart-service/noshipments?pageNum=1&pageSize=10000&userId=" + res.id,
					async: true,
					success: function(data) {
							console.log(data)
						$.each(data.list, function(idx, item) {
								console.log(item)
							if(idx == data.list.length - 1) {
								var lis = '<li>' +
									'<div class="gift_left foods_detail_pic">' +
									'<img src="' + item.goodsPic + '"/>' +
									'</div>' +
									'<div class="gift_right">' +
									'<p id="shopName">' + item.goodsName + '</p>' +
									'<p id="shopPrice">金币:' + item.goodsgold + '&nbsp;&nbsp;数量' + item.goodsCount + '</p>' +
									'<p><input type="hidden" name="check" id="check"  value="' + item.cartId + '"/>&nbsp;&nbsp;&nbsp;&nbsp; ' +
									//									'<button class="del">删除</button></p>'++
									'</div>' +
									'<div class="duihuan">' +
									'<img src="../../../images/store/duihuan.png"/>' +
									'</div>' +
									'</li>'
								$(".gift_sell_wap ul").append(lis);
							}
						});

					}
				});

			}
		});
		//发货
		$("#fahuo").on("click", function() {
			//登陆信息
			$.ajax({
				type: "get",
				url: "http://47.104.13.109/member-service/auth/current?token=" + $.cookie("tokenRh"),
				async: true,
				success: function(res) {
					//	console.log(res)
					var cartId = $('input:hidden').val();
					console.log(cartId)
						//用户申请发货
					$.ajax({
						type: "post",
						url: "http://47.104.13.109/cart-service/goldupdate?Cartid=" + cartId,
						async: true,
						success: function(res1) {
							console.log(res1)

							// 查询商品信息	
							console.log(Request.goodsId)
							$.ajax({
								type: "get",
								url: "http://47.104.13.109/cart-service/selecdetail?goodsId=" + Request.goodsId,
								async: true,
								success: function(data) {
									console.log(data)
										//生成订单
									$.ajax({
										type: "post",
										url: "http://47.104.13.109/order-service/addgold",
										async: true,
										data: {
											goodsId: data["0"].goodsId,
											goodsNum: data["0"].goodsNum,
											goodsName: data["0"].goodsName,
											goodsGold: data["0"].goodsgold * $("#shopNum").html(),
											goodsCatid: data.goodsCatid,
											goodsPic: data["0"].goodsPic,
											goodsIntro: data["0"].goodsIntro,
											goodsCount: data["0"].goodsCount,
											userId: res.id,
											userName: res.loginName,
											userPhone: res.tel,
											cartId: cartId
										},
										success: function(aa) {
											console.log(aa)
											alert("发货成功");
											window.location.href = '../store_gold/index.html';

										},
										error:function(error){
											console.log(error);
										}
									});

								}
							})
						}
					});

					
				}
			});

		})
	</script>

</html>